package com.enbatis.mybatisplugs.service.impl;

import com.enbatis.mybatisplugs.base.BaseServiceImpl;


import com.enbatis.mybatisplugs.commons.utils.IdWorker;
import com.enbatis.mybatisplugs.commons.utils.MD5Util;
import com.enbatis.mybatisplugs.commons.utils.ResultReturn;
import com.enbatis.mybatisplugs.entity.SysUser;
import com.enbatis.mybatisplugs.mapper.SysUserMapper;
import com.enbatis.mybatisplugs.service.SysUserService;
import org.springframework.stereotype.Service;

/**
* 描述：
* @author wangweidong
* @date 2019-06-15 10:31:25
*/

@Service
public class SysUserServiceImpl extends BaseServiceImpl<SysUserMapper, SysUser> implements SysUserService {


    @Override
    public boolean insertUser(SysUser user) {

        String psd=user.getPassword();
        String salt= MD5Util.getSalt(psd);
        user.setPassword(MD5Util.generatePsd(psd,salt));
        user.setSalt(salt);

        try {
            this.insert(user);
        }catch (Exception e){
            String message= e.getMessage();
            if (message.contains("unique_username")){
                return false;
            }
        }

        return true;
    }
}
